<!DOCTYPE html>
<html>
<head>
    <title>咨询医师</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
    <meta name="description" content="">
    <link rel="stylesheet" href="/lib/weui.min.css">
    <link rel="stylesheet" href="/css/jquery-weui.css">
    <link rel="stylesheet" href="/plugins/fontaw/css/font-awesome.css">
    <link rel="stylesheet" href="/plugins/kim/style.css">
    <style>
        html{font-size:16px;color: #3a3a3a; }
        header{height:2.5rem;display: flex;line-height: 2.5rem;border-bottom: rgba(10,10,10,.2) solid 1px;position: fixed;top:0rem;
        width: 100%;z-index: 99}
        header nav{flex: 1;text-align: center;background-color: white}
        header .currntNav{color:darkred;border-bottom: darkred solid 0.2rem;background-color: white}
        section{position: fixed;top:2.5rem;bottom:7.2rem;width: 100%;height: 100%;display: none}

        footer{position: fixed;bottom: 0rem;height: 95px;width: 100%;background-color: white}
        .reply-tools{display: -webkit-box;width: 100%; display: flex;padding:0rem 0.5rem}
        .reply-input{width: 95%;height: 36px;border-radius: 0.6rem;border: #cccccc solid 1px;padding:0rem 0.5rem;font-size:16px}
        .w-8{width:80%;padding:0.3rem}
        .w-2{width:20%;padding:0.3rem}
        .reply-links{padding:0.4rem  0.9rem 0.2rem 0.9rem;display:-webkit-inline-box}
        .reply-links a{color: #4b4a48}
        .link-block{flex:1;text-align: center}
        .link-block i{font-size:36px;display: inline-block;color: grey}
        .link-block span{display: table-cell;font-size: 14px;text-align: center;display: inline-block; border:#3d4145 solid 1px;
            border-radius: 8px;margin-right: 0.5rem;padding:0.1rem 0.3rem }
        .reply-btn{
            background-color: lightgreen;
            border: forestgreen solid 1px;
            border-radius: 0.2rem;
            height: 36px;
            line-height: 36px;
            width: 80%;
            text-align: center;
            vertical-align: middle
        }

        .inquir-history{
            overflow-y: scroll;
        }
        .chat-zone{
            display: none;
            position: relative;
        }
        .patient-info{position: relative;background-color: white;width: 95%;margin-top: 0.5rem;
        padding:0.5rem}
        .div-avatar{position: absolute;top:0.5rem;left:1rem}
        .div-avatar img{border-radius: 50%}
        .div-basic{margin-left: 5rem;}
        .info-name{height: 2rem;line-height: 2rem;padding-left: 0.8rem}
        .info-wechat{color: grey;font-size: 16px;padding-left: 0.8rem;font-size:12px}
        .info-wechat i{width: 1rem}
        .more-inquiry{ text-align: center;color: #1aad19;height: 3rem; line-height: 3rem}
        .more-inquiry i{ width: 1.2rem}
        .history-list{margin-top: 0.5rem;padding: 0.5rem;}
        .history-block{border: #ededec solid 1px; border-radius: 0.3rem;min-height: 4rem;margin-bottom: 0.5rem;background-color: white;}
        .history-block-head{padding: 0.2rem 0.5rem;border-bottom: #ededec solid 1px;padding-bottom: 5px}
        .right-tip{float: right; border-radius: 0.6rem;border: #e1e1e1 solid 1px;font-size: 16px;line-height: 0.8rem;margin-top: 0.6rem;padding: 0.2rem}
         .history-block-body{padding:0.2rem;font-size: 14px;}
        .history-block-body span{margin-right: 0.4rem;color: grey;text-align: justify;width: 3.5rem;display:inline-block; text-align-last:justify;}
        .history-block-body span:after{  content: ":";/* 放大镜符号 */font-size: 14px;}
        .history-block-body p{overflow: hidden;white-space: nowrap;text-overflow: ellipsis;margin: 0.3rem}
        .history-block-foot{text-align: center;padding: 0.3rem;border-top:#f5f5f5 dashed 1px }
        .history-block-foot a{color: grey;font-size: 14px}
        .box-head-span{padding-left:5px}

        .message{padding:0.5rem;color:#4b4a48}
        .message-mid-line{text-align: center;color:#cccccc;font-size: 16px;margin-bottom: 0.2rem}
        .message-box{display: flex}
        .user-avatar{}
        .user-avatar img{ border-radius: 50%;width: 2.4rem}
        .message-content{font-size: 16px;margin: 0rem 0.5rem;}

        .message-top{background-color: white;border-radius: 0.2rem;padding:0.4rem;height: 30px;line-height: 30px;display: inline-table}
        .message-top:before{
            content: ' ';
            position: absolute;
            top: 11px;
            border-top: 5px solid transparent;
            border-bottom: 5px solid transparent;
            width: 0;
            height: 0;
        }
        .me{background-color: lightgreen}
        .orange-title{background-color: orange}
        .doc{width: 13rem}
        .span-right{float:right;color: grey;font-size: 16px}
        .message-content-body{background-color: white;font-size: 16px;padding:0.4rem}
        .message-content-body p{margin: 0rem}
        .message-content-body span{color: grey}
        .message-content-foot{text-align: center;font-size:14px;color:#cccccc;border-top: #e1e1e1 solid 1px;background-color: white;padding:0.1rem}
        .f-right{float: right}
        .chat-content{position: fixed;top:2.5rem;bottom:95px;overflow-y: scroll;width:100%}

        .weui-loadmore{
            width:65%;
            margin:1.5em auto;
            line-height:1.6em;
            font-size:14px;
            text-align:center;
        }

        .weui-loadmore_line{
            border-top:1px solid #E5E5E5;
            margin-top:2.4em;
        }
        .weui-loadmore_dot .weui-loadmore__tips{
            padding:0 .16em;
        }
        .weui-loadmore_dot .weui-loadmore__tips:before{
            content:" ";
            width:4px;
            height:4px;
            border-radius:50%;
            background-color:#E5E5E5;
            display:inline-block;
            position:relative;
            vertical-align:0;
            top:-0.16em;
        }
        .weui-loadmore_line .weui-loadmore__tips{
            position:relative;
            top:-0.9em;
            padding:0 .55em;
            background-color:#FFFFFF;
            color:#999999;
        }
        .sub-title{font-size:14px;color:grey}
        .extra-zone{border-top: #fcfcfb;height:80px;margin-top:1.4rem;background-color: #fcfcfd;display: flex;text-align: center;color: grey}
        .extra-box{flex: 1;padding:10px 0px 15px 0px}
        .extra-box i{font-size:32px;display: block; }
        .extra-box span{font-size:16px;display: block ;margin-top:5px}
        .hor-line{ border-left: #E9E9E9 dashed 1px;width: 1px}
        .box-head{padding:0px 3px;border-bottom: #F7F7F7 solid 1px;padding-bottom: 5px}
        .box-body{padding:5px 3px;font-size: 14px;color: grey}
        .tiny-text{font-size: 12px;}
        .grey{color: grey}
        .doctor-detail{overflow-y: scroll}
    </style>
</head>
<body>
<header>
    <nav  target="doctor-detail">医生详情</nav>
    <nav target="chat-zone" class="currntNav">咨询</nav>
    <nav target="inquir-history">我的病例</nav>
</header>

<section class="doctor-detail" >
    <div class="patient-info">
        <div class="div-avatar">
            <img src="/mod-page/images/avatar-icon.png" style="width:3.5rem" class="uavatar">
        </div>
        <div class="div-basic">
            <div class="info-name">
                <span id="doctorName" style="font-weight: bold"></span> <span class="sub-title"> 医师 </span>
            </div>
            <div class="info-wechat">
                <p id="address"><!--<i class="fa fa-building" aria-hidden="true"></i></i> 浙江 金华--></p>
            </div>
        </div>
        <div class="extra-zone">
            <div class="extra-box">
                 <i class="fa fa-user-md" aria-hidden="true"></i>
                 <span>门诊</span>
            </div>
            <div class="hor-line"></div>
            <div class="extra-box">
                <i class="fa fa-thumbs-up" aria-hidden="true"></i>
                <span>赞赏</span>
            </div>
            <div class="hor-line"></div>
            <div class="extra-box">
                <i class="fa fa-share-alt-square" aria-hidden="true"></i>
                <span>分享</span>
            </div>
        </div>
    </div>
    <div class="patient-info">
        <div class="box-head">
            <div> <span style="color: darkred;">中医线上咨询</span>
                <span class="f-right" style="color: grey;">￥20/次</span></div>
            <div>
                <span class="tiny-text grey">
                    <!--当前咨询费用是免费，如果满意记得赞Ta -->
                    填写问诊单时支付费用
                </span>
            </div>
        </div>
        <div class="box-body" id="notice_description">
            <!--<p>
                kriss:咨询量大，假发讲述了发卡上的浪费看见爱上了咖啡，是打发了反馈了房间爱丽丝快递费 沙发了卡讲述了饭卡上剪短发了空间
            </p>-->
        </div>
    </div>

    <div class="patient-info">
        <div class="box-head">
            <div>
                <i class="fa fa-volume-up" aria-hidden="true"></i> <span style="padding-left: 10px"> 医生公告 </span>
            </div>
        </div>
        <div class="box-body" id="notice_content">
            <!--<p>
               111
            </p>-->
        </div>
    </div>

    <div class="patient-info">
        <div class="box-head">
            <div>
                <i class="fa fa-medkit" aria-hidden="true"></i> <span style="padding-left: 10px"> 擅长主治 </span>
            </div>
        </div>
        <div class="box-body" id="notice_specialty">
            <!--<p>
                111
            </p>-->
        </div>
    </div>

    <div class="patient-info">
        <div class="box-head">
            <div>
                <i class="fa fa-briefcase" aria-hidden="true"></i> <span style="padding-left: 10px"> 简介 </span>
            </div>
        </div>
        <div class="box-body" id="notice_introduce">
            <!--<p>
                111
            </p>-->
        </div>
    </div>

    <div class="patient-info">
        <div class="box-head">
            <div>
                <i class="fa fa-building" aria-hidden="true"></i> <span style="padding-left: 10px"> 门诊信息 </span>
            </div>
        </div>
        <div class="box-body" id="clinicInfo">
            <!--<p>杭州市第五人民医院</p>
            <p>门诊地址：杭州市拱墅区大观路288号 水晶城三楼</p>
            <p>联系方式：1378888999</p>-->
        </div>
    </div>

    <div style="height: 60px"></div>
</section>


<section class="chat-zone" style="display: block">
    <div class="chat-content" id="chat-content">
        <div class="weui-loadmore">
            <i class="weui-loading"></i>
            <span class="weui-loadmore__tips">聊天记录加载中...</span>
        </div>
    </div>
    <footer class="" id="foot">
        <div class="reply-links">
            <div class="link-block">
                <a href="javascript:;">   <span>填写问诊单</span></a>
            </div>
            <div class="link-block">
               <a href="javascript:;" onclick="clinicInfo()"> <span>门诊信息</span> </a>
            </div>

            <div class="link-block" >
                <a href="javascript:;" id="chat-img">   <span>图片</span></a>
            </div>

            <div class="link-block">
                <a href="javascript:;" onclick="doctorUp()">  <span>赞赏</span></a>
            </div>

            <div class="link-block">
                <a href="javascript:;">  <span>收费说明</span></a>
            </div>
        </div>
        <div class="reply-tools">
            <div class="w-8"><input class="reply-input" /></div>
            <div class="w-2"><a ><div class="reply-btn">发送</div></a></div>
        </div>
    </footer>
</section>


<section class="inquir-history" >
    <div class="patient-info">
        <div class="div-avatar">
            <img src="/mod-page/images/avatar-icon.png" style="width:4rem" id="patientAvatar" />
        </div>
        <div class="div-basic">
            <div class="info-name">
                <span id="patientName"></span>
            </div>
            <div class="info-wechat">
                <p><i class="fa fa-wechat" aria-hidden="true"></i> <span id="patientWCName"></span></p>
                <p><i class="fa fa-phone-square" aria-hidden="true"></i> <span id="patientPhone"></span></p>
            </div>
        </div>
    </div>

    <div class="history-list" id="history_list">
        <div class="history-block">
            <div class="history-block-head">
                <i class="fa fa-reorder" aria-hidden="true" style="color:darkred"></i> <span class="box-head-span">方案 </span>
            </div>
            <div class="history-block-body">
                <p><span>患者</span>sss，34岁</p>
                <p><span>病、症名</span>大幅度发</p>
                <p><span>方案收费</span>大幅度发</p>
                <p><span>处方</span>费大幅度发asdfas是的发送到发送到发生的方式地方官史蒂夫是的分公司电饭锅</p>
                <p><span>贴数</span>分公司电饭锅</p>
                <p><span>开方时间</span>大幅度发</p>
            </div>
            <div class="history-block-foot"><a href="javascript:;">点击查看详情</a></div>
        </div>
        <!--<div class="history-block">
            <div class="history-block-head">
                <i class="fa fa-question-circle-o" aria-hidden="true" style="color: orange;font-size: 18px"></i> <span class="box-head-span">问诊单 </span>
            </div>
            <div class="history-block-body">
                <p><span>患者</span>sss，34岁</p>
                <p><span>患者主诉</span>大幅度发</p>
                <p><span>身体感觉</span>大幅度发</p>
                <p><span>填写时间</span>2018-11-13</p>
            </div>
            <div class="history-block-foot"><a href="javascript:;">点击查看详情</a></div>
        </div>-->
        <div style="height: 3rem">
        </div>
    </div>
</section>

<div id="full" class='weui-popup__container' style="z-index: 9999">
    <div class="weui-popup__overlay"></div>
    <div class="weui-popup__modal">
        <iframe src="" width="100%" height="100%" frameborder="0" id="innerFrame" style="overflow: auto"></iframe>
    </div>
</div>

<script src="/lib/jquery-2.1.4.js"></script>
<!-- websocket -->
<script src="/plugins/websocket/sockjs.min.js"></script>
<script src="/plugins/websocket/stomp.min.js"></script>
<script src="/js/jquery-weui.js"></script>
<script type="text/javascript" src="/plugins/cropper/js/lrz.all.bundle.js"></script>
<script src="/js/home.js"></script>
<script>
    var fromId = getQueryString("patientId");
    var toId =  getQueryString("doctorId");

    var defaultDocAvatar= "/mod-page/images/avatar2.jpg";
    var defaultPatientAvatar = "/mod-page/images/avatar3.jpg";

    var tag= getQueryString("tag");

    $(document).ready(function(){
        if(tag){
            if("doctorInfo"==tag){
                $(".inquir-history").hide();
                $(".chat-zone").hide();
                $(".doctor-detail").show();
                $("nav").removeClass("currntNav");
                $("nav[target='doctor-detail']").addClass("currntNav");
            }else if("chat"==tag){
                $(".inquir-history").hide();
                $(".doctor-detail").hide();
                $(".chat-zone").show();
                $("nav").removeClass("currntNav");
                $("nav[target='chat-zone']").addClass("currntNav");
            }
        }

        $("nav").click(function(){
            $("nav").removeClass("currntNav");
            $(this).addClass("currntNav");
            if($(this).attr("target")=="inquir-history"){
                $(".chat-zone").hide();
                $(".doctor-detail").hide();
                $(".inquir-history").show();

            }else if($(this).attr("target")=="chat-zone"){
                $(".inquir-history").hide();
                $(".doctor-detail").hide();
                $(".chat-zone").show();
            }else if($(this).attr("target")=="doctor-detail"){
                $(".inquir-history").hide();
                $(".chat-zone").hide();
                $(".doctor-detail").show();
            }
            toBottom();
        });
        $(".reply-btn").click(sendWS);
        loadDocInfo();
        loadPatientInfo();
        setTimeout(loadChatHistory,1000);

        $("#chat-img").h5uploadSilence({
            exts: ['jpg', 'gif', 'png', 'jpeg'],
            size: 10145728,
            restric:false,
            hideSelect:true,
            name: 'idImage',
            callback:function(b64ImgData){
                wrapImageMsg(b64ImgData);

                var text = window.atob(b64ImgData.split(",")[1]);
                var buffer = new ArrayBuffer(text.length);
                var ubuffer = new Uint8Array(buffer);
                for (var i = 0; i < text.length; i++) {
                    ubuffer[i] = text.charCodeAt(i);
                }
                var Builder = window.WebKitBlobBuilder || window.MozBlobBuilder;
                var blob;
                if (Builder) {
                    var builder = new Builder();
                    builder.append(buffer);
                    blob = builder.getBlob("image/jpeg");
                } else {
                    blob = new window.Blob([buffer], {type: "image/jpeg"});
                }

                var formData = new FormData();
                formData.append("img",blob);
                formData.append("bizType","chatImg");

                $.ajax({
                    url:"/im/uploadChatImg",
                    type:"post",
                    data:formData,
                    processData: false,
                    contentType: false,
                    success:function(da){
                        console.log(da.data);
                        var jsonMsg={"toId":toId,"fromId":fromId,"msg":da.data,"clientType":"patient","msgType":"img"};
                        stompClient.send("/ws/p2pchat", {}, JSON.stringify(jsonMsg));
                    }
                });
            }
        });

        $(".reply-input").focus(function(){
            setTimeout(function(){
                document.getElementById("foot").scrollIntoView(true);// 参数可以是true， false, 空参数
            }, 300);
        });
    });

    var doctorLoaded = false;
    var patientLoaded = false;
    function loadChatHistory(){
        $.ajax({
            url:"/im/loadMyMessages",
            data:{"whos":"patient","fromId":fromId,"toId":toId},
            success:function(da){
                $("#chat-content").html("");
                if(da.msg == "ok"){
                    var chatCnt= $(da.data.rows).length;
                    if(chatCnt==0){

                    }else{
                        $(da.data.rows).each(function (i){
                            if(i==0){
                                midTipMessage(this.sendTime);
                            }
                            if(this.whos=="doctor"){
                                if(this.msgType=="img")
                                    wrapImageOherMsg(this.msgContent);
                                else
                                    wrapOtherTextMsg(this.msgContent);
                            }else if(this.whos=="patient"){
                                if(this.msgType=="img")
                                    wrapImageMsg(qiniuChatImgDomain+"/"+this.msgContent);
                                else
                                    wrapMyTextMsg(this.msgContent);
                            }
                        });
                        midTipMessage("以上是历史数据");
                        $(".chat-content").append("<div style='height: 10px' id='btom'></div>");
                        setTimeout(function(){
                            document.getElementById("btom").scrollIntoView(true);// 参数可以是true， false, 空参数
                        }, 300);

                    }

                }
            }
        });

    }

    function midTipMessage(msg){
        $("#chat-content").append("<div class=\"weui-loadmore weui-loadmore_line\" style='margin-bottom: 0.3rem'>\n" +
            "        <span class=\"weui-loadmore__tips\">"+msg+"</span>\n" +
            "      </div>");
    }

    var stompClient ;

    var login = {login:fromId}
    function connectToWebSocket() {
        var socket = new SockJS("/chatServer");
        stompClient = Stomp.over(socket);
        stompClient.connect(login, function(frame) {
            console.log('Connected: ' + frame);
            stompClient.subscribe('/user/chat/backMsg', function (da) {
               var resp =  JSON.parse(da.body);
               if(resp.msgType=="text")
                   wrapOtherTextMsg(resp.msg);
               else if(resp.msgType=="img")
                   wrapImageOherMsg(resp.msg);
            });

        });
    }
    connectToWebSocket();
    function sendWS(){
        var wsMsg = $(".reply-input").val();
        if(wsMsg==""){
            $.toast("内容不能为空","text");
            return;
        }
        var jsonMsg={"toId":toId,"fromId":fromId,"msg":wsMsg,"clientType":"patient","msgType":"text"};
        stompClient.send("/ws/p2pchat", {}, JSON.stringify(jsonMsg));
        $(".reply-input").val("");
        wrapMyTextMsg(wsMsg);
    }

    function loadDocInfo(){
        $.ajax({
            url:"/d/doctor/getDoctorInfo",
            data:{"doctorId":toId},
            dataType:"json",
            success:function (da){
                if(da.data){
                    doctorInfo =da.data;
                    defaultDocAvatar = da.data.picPath;
                    $(".uavatar").attr("src",da.data.picPath);
                    $("#doctorName").html(da.data.doctorname);

                    doctorLoaded = true;
                }
            }
        });
    }

    function loadPatientInfo(){
        $.ajax({
            url:"/patient/getPatientById",
            data:{"patientId":fromId},
            dataType:"json",
            success:function (da){
                if(da.data){
                    defaultPatientAvatar = da.data.patientPicPath;
                    $("#patientName").text(da.data.patientname);
                    $("#patientAvatar").attr("src",defaultPatientAvatar);
                    $("#patientWCName").text(da.data.patientname);
                    $("#patientPhone").text(da.data.phone);
                    patientLoaded = true;
                }
            }
        });
    }

    function wrapMyTextMsg(msg){
        var html= "<div class=\"message\">\n" +
            "    <div class=\"message-mid-line\"></div>\n" +
            "    <div class=\"message-box f-right\">\n" +
            "            <div class=\"message-content  \" style='display: inline-flex'>\n" +
            "                <div class=\"message-top me\">"+msg+"</div>\n" +
            "            </div>\n" +
            "            <div class=\"user-avatar\">\n" +
            "                <img src=\""+defaultPatientAvatar+"\" />\n" +
            "            </div>\n" +
            "    </div>\n" +
            "  <div style=\"clear: both\"></div>" +
            "</div>";
        $(".chat-content").append(html);
        toBottom();
    }

    function wrapOtherTextMsg(msg){
        var html= "<div class=\"message\">\n" +
            "    <div class=\"message-mid-line\"></div>\n" +
            "    <div class=\"message-box\">\n" +
            "            <div class=\"user-avatar\">\n" +
            "                <img src=\""+defaultDocAvatar+"\" />\n" +
            "            </div>\n" +
            "            <div class=\"message-content\" style='display: inline-flex'>\n" +
            "                <div class=\"message-top\">"+msg+"</div>\n" +
            "            </div>\n" +
            "    </div>\n" +
            "    <div style=\"clear: both\"></div>\n" +
            "</div>"
        $(".chat-content").append(html);
        toBottom();
    }

    function wrapImageMsg(img){
        var html= "<div class=\"message\">\n" +
            "    <div class=\"message-mid-line\"></div>\n" +
            "    <div class=\"message-box f-right\">\n" +
            "            <div class=\"message-content  \" style='display: inline-flex'>\n" +
            "                <div class=\"message-top me\" style='padding:0rem;background-color: unset'><img src=\""+img+"\" width=\"200\"/></div>\n" +
            "            </div>\n" +
            "            <div class=\"user-avatar\">\n" +
            "                <img src=\""+defaultPatientAvatar+"\" />\n" +
            "            </div>\n" +
            "    </div>\n" +
            "  <div style=\"clear: both\"></div>" +
            "</div>";
        $(".chat-content").append(html);
        toBottom();
    }
    function wrapImageOherMsg(img){
        var html= "<div class=\"message\">\n" +
            "    <div class=\"message-mid-line\"></div>\n" +
            "    <div class=\"message-box\">\n" +
            "            <div class=\"user-avatar\">\n" +
            "                <img src=\""+defaultDocAvatar+"\" />\n" +
            "            </div>\n" +
            "            <div class=\"message-content\">\n" +
            "                <div class=\"message-top\" style='padding:0rem;background-color: unset'><img src=\""+qiniuChatImgDomain+"/"+img+"\" width=\"200\"/></div>\n" +
            "            </div>\n" +
            "    </div>\n" +
            "    <div style=\"clear: both\"></div>\n" +
            "</div>";
        $(".chat-content").append(html);
        toBottom();
    }

    function getQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return decodeURI(r[2]);
        return "";
    }

    function toBottom(){
       /*  var div = document.getElementById('chat-content');
      // div.scrollTop = div.scrollHeight+660;*!/
        $(".chat-content").scrollTop(div.scrollHeight+200)*/

        $("#btom").appendTo($(".chat-content"));
        setTimeout(function(){
            document.getElementById("btom").scrollIntoView(true);// 参数可以是true， false, 空参数
        }, 300);
    }

    function clinicInfo(){
        location.href="/mod-page/studio/list_clinic_for_patient.html?doctorId="+toId;
    }

   function doctorUp(){
       /*$("#innerFrame").attr("src","/wcpay/doctor_up.html?doctorId="+toId+"&patientId="+fromId);
       $("#full").popup();*/
       location.href="/wcpay/doctor_up.html?doctorId="+toId+"&patientId="+fromId;
   }
    $(function(){
       var doctorData = {"doctorId":toId};
        // 加载医生信息
        $.ajax({
            url:"/d/doctor/getDoctorInfo",
            type:"post",
            data:doctorData,
            dataType:"json",
            success:function(result){
                $("#address").html("<i class='fa fa-building' aria-hidden='true'></i></i>"+result.data.address);
                $("#notice_description").html("<p>"+result.data.doctorname+"："+result.data.notice.welcomeWords+"</p>");
                $("#notice_content").html("<p>"+result.data.notice.notice+"</p>");
                $("#notice_specialty").html("<p>"+result.data.notice.goodAt+"</p>");
                $("#notice_introduce").html("<p>"+result.data.notice.introduce+"</p>");
                $("#clinicInfo").html("<p>"+result.data.clinic.clinicname+"</p><p>门诊地址："+result.data.clinic.adddetail+"</p><p>联系方式："+result.data.clinic.contact+"</p>");
            },error:function(){
                console.log("ajax error")
            }
        });
        var patientData = {"patientId":fromId};
        var historyList = "";   // 存储患者的历史记录列表（问诊单，方案）
        // 加载患者信息
        $.ajax({
            url: "/inquiry/selectByPatientId",
            type: "post",
            data: patientData,
            dataType: "json",
            success: function (result) {
                $(result.data).each(function(i){
                   console.log(this.description)
                    historyList += "<div class='history-block'><div class='history-block-head'><i class='fa fa-question-circle-o' aria-hidden='true' style='color: orange;font-size: 18px'></i> <span class='box-head-span'>问诊单 </span>"+
                            "</div><div class='history-block-body'><p><span>患者</span>"+this.patient.patientname+"，"+this.patient.sex+"，"+this.patient.age+"岁</p><p><span>患者主诉</span>"+this.description+"</p><p><span>填写时间</span>"+timestampToTime(this.createDate)+"</p>"+
                            "</div><div class='history-block-foot'><a href='javascript:;'>点击查看详情</a></div></div>";
                });
                $("#history_list").html(historyList);
            }, error: function () {
                console.log("ajax error")
            }
        });
    });

    // 时间戳转日期格式
    function timestampToTime(timestamp) {
        var date = new Date(timestamp);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
        Y = date.getFullYear() + '-';
        M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
        D = date.getDate() + ' ';
        h = date.getHours() + ':';
        m = date.getMinutes() + ':';
        s = date.getSeconds();
        if(h=="0:" && m=="0:" && s=="0"){
            return Y+M+D;
        }
        return Y+M+D+h+m+s;
    }
</script>
</body>
</html>
